<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/7
 * Time: 14:22
 */

namespace app\admin\controller;


use think\Controller;
use think\Session;

class BaseController extends Controller
{
    protected $middleware=[];

    protected $beforeActionList = [
        "checkLogin",
        "checkScope"    =>["only"   =>"page"]
    ];

    public function checkLogin(){
        $user=(new Session())->get("user");
        //dump($user);die();
        if(!isset($user)){
            $this->error("您还没有登陆！");
        }
    }

    public function checkScope(){
        $user=(new Session())->get("user");
        $controller=$this->request->controller();
        $arr=[
            "Store.stayIn"
        ];
        switch ($user["scope"]){
            case 0://普通用户
                if(in_array($controller,$arr)){
                    return $this->error("权限不够",url("index/index"));
                }
                break;
            case 1://超级管理员

                break;
            default:

                if(in_array($controller,$arr)){
                    return $this->error("权限不够",url("index/index"));
                }
                break;
        }
    }

}